﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GQ.Controls;
using GQ.Utils.TreeNode;
using GQ.BLL.Category;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.Controls;

namespace GQ.QuanLyKho
{
    public class Singleton
    {
        static Singleton _install;
        public const string LoaiHang = "00000000-0000-0000-0000-000000000041";
        //public const string TinhChatHangHoa = "00000000-0000-0000-0000-000000000005";

        static Singleton()
        {
            _install = new Singleton();
        }
        public Singleton()
        {

        }
        string _prefix = null;
        public static string Prefix
        {
            get
            {
                if (string.IsNullOrEmpty(_install._prefix))
                    return GQ.WinForms.Singleton.GetPrefix("GQ.Contest");
                else return _install._prefix;
            }
        }
        public static void FillRepositoryItemImageComboBox(RepositoryItemImageComboBox cboImange,string id )
        {
            NodeCollection nodes = new NodeCollection();
            string sfmWhere = "ID={0} sortby OrderID";
            IList<CategoryType> categorys = CategoryType.LoadAllBy(sfmWhere, id);
            foreach (INode item in categorys)
            {
                nodes.Add(item);
            }
            FillComboImage(cboImange, nodes);
        }
        private static void FillComboImage(RepositoryItemImageComboBox cboImg, NodeCollection nodes)
        {
            foreach (INode item in nodes)
            {
                cboImg.Items.Add(new  ImageComboBoxItem(item.Text,item.ID,-1));
                if(item.Children.Count>0)
                {
                    FillComboImage(cboImg,item.Children);
                }
            }
        }

        public static void FillCategory(ComboboxTree combobox, string id)
        {
            NodeCollection nodes = new NodeCollection();
            string sfmWhere = "ID={0} sortby OrderID";
            IList<CategoryType> categorys = CategoryType.LoadAllBy(sfmWhere, id);
            foreach (INode item in categorys)
            {
                nodes.Add(item);
            }
            combobox.LoadDataTree(nodes);
        }
    }
}
